//package ua.kharkiv.khpi.tarasenko.diploma.analysis.test;
//
//import java.io.IOException;
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Set;
//
//import org.apache.log4j.Logger;
//
//import ua.kharkiv.khpi.tarasenko.diploma.analysis.approach.AnalysisApproach;
//import ua.kharkiv.khpi.tarasenko.diploma.analysis.approach.RulesGenerator;
//import ua.kharkov.khpi.tarasenko.bach.analysis.Prefixspan.Item;
//import ua.kharkov.khpi.tarasenko.bach.analysis.Prefixspan.Node;
//import ua.kharkov.khpi.tarasenko.bach.analysis.Prefixspan.PseudoDB;
//import ua.kharkov.khpi.tarasenko.bach.analysis.Prefixspan.Sequence;
//import ua.kharkov.khpi.tarasenko.bach.core.logging.TransactionType;
//
//public class SolutionTester {
//
//	private static enum DB_TYPE {
//		TRAIN, TEST;
//	}
//
//	private static final Logger LOG = Logger.getLogger(SolutionTester.class);
//
//	private static final double PERCENTAGE_OF_TRAIN_SET = 0.75;
//
//	private final PseudoDB db;
//	private final int minSup;
//
//	public SolutionTester(PseudoDB db, int minSup) {
//		this.db = db;
//		this.minSup = minSup;
//	}
//
//	public double testSolution() throws IOException {
//
////		PseudoDB prunedDB = AnalysisUtils.removeNonBuySessions(db);
//
//		Map<DB_TYPE, PseudoDB> initialDB = getTrainAndTestDB(db);
////
////		LOG.debug(DB_TYPE.TRAIN + "\n" + initialDB.get(DB_TYPE.TRAIN));
////		LOG.debug(DB_TYPE.TEST + "\n" + initialDB.get(DB_TYPE.TEST));
//
//		// TRAIN TODO!
//		Node rootNode = approach.analyze(initialDB.get(DB_TYPE.TRAIN), minSup);
//		System.out.println("Item: "+ Item.toSize.size());
//		
//		
//		Sequence currentSeq = new Sequence();
//		Item item = Item.getItem("14379");
//		item.setTransactionType(TransactionType.VIEW);
//		currentSeq.addItem(item);
//
//		
//		RulesGenerator rg = new RulesGenerator(rootNode, 0, 100, 3);
//		Set<Item> recs = rg.getRecommendation(currentSeq);
//		System.out.println("=========================================");
//		for (Item rItem : recs) {
//			System.out.println(rItem);
//		}
//		
//		return 0;
//	}
//
//	private Map<DB_TYPE, PseudoDB> getTrainAndTestDB(PseudoDB dbToOperate) {
//		Map<DB_TYPE, PseudoDB> dbs = new HashMap<DB_TYPE, PseudoDB>();
//
//		LOG.debug("Start db:\n");
//		LOG.debug(dbToOperate);
//
//		int initialSize = dbToOperate.getRows().size();
//		LOG.debug("initialSize=" + initialSize);
//		double targetTrainSetSize = Math
//				.floor(((double) initialSize * PERCENTAGE_OF_TRAIN_SET));
//		LOG.debug("targetTrainSetSize=" + targetTrainSetSize);
//		double currentSize = 0d;
//
//		ArrayList<Sequence> shuffledList = new ArrayList<Sequence>(dbToOperate.getRows());
//		Collections.shuffle(shuffledList);
//
//		PseudoDB trainDB = new PseudoDB();
//		PseudoDB testDB = new PseudoDB();
//		for (Sequence row : shuffledList) {
//			if (currentSize < targetTrainSetSize) {
//
//				// fill train db
//				trainDB.addRow(row);
//				currentSize++;
//			} else {
//
//				// fill test db
//				testDB.addRow(row);
//			}
//		}
//
//		dbs.put(DB_TYPE.TEST, testDB);
//		dbs.put(DB_TYPE.TRAIN, trainDB);
//		return dbs;
//	}
//
//}